package io.adrainty.bolee.insurance.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResponseCode;
import io.adrainty.bolee.framework.commons.exception.AppException;
import io.adrainty.bolee.insurance.models.entity.CoefficientEntity;
import io.adrainty.bolee.insurance.repository.ICoefficientRepository;
import io.adrainty.bolee.insurance.service.ICoefficientService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>CoefficientServiceImpl</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description ICoefficientService
 * @since 2025/8/11 10:23:06
 */

@Service
public class CoefficientServiceImpl implements ICoefficientService {

    @Resource
    private ICoefficientRepository coefficientServiceRepository;

    @Override
    public IPage<CoefficientEntity> findCoefficientPage(Integer pageNum, Integer pageSize, CoefficientEntity searchDTO) {
        return coefficientServiceRepository.findCoefficientPage(pageNum, pageSize, searchDTO);
    }

    @Override
    public List<CoefficientEntity> findCoefficientList(CoefficientEntity entity) {
        return coefficientServiceRepository.findCoefficientList(entity);
    }

    @Override
    public CoefficientEntity createCoefficient(CoefficientEntity entity) {
        if (!coefficientServiceRepository.createCoefficient(entity)) {
            throw new AppException(ResponseCode.COEFFICIENT_CREATE_ERROR);
        }
        return entity;
    }

    @Override
    public Boolean updateCoefficient(CoefficientEntity entity) {
        if (entity.getId() == null) {
            throw new AppException(ResponseCode.ILLEGAL_PARAMETER);
        }
        return coefficientServiceRepository.updateCoefficient(entity);
    }

    @Override
    public Boolean deleteCoefficient(List<String> deleteIdList) {
        return coefficientServiceRepository.deleteCoefficient(deleteIdList);
    }

    @Override
    public CoefficientEntity findByCoefficientKey(String coefficientKey) {
        return coefficientServiceRepository.findByCoefficientKey(coefficientKey);
    }

}
